import axios from '/ssm/static/js/axios.min.js';

// 创建 axios 实例
const service = axios.create({
  baseURL: '/', // api base_url
  timeout: 6000 // 请求超时时间
})

const err = (error) => {
  if (error.response) {
    let data = error.response.data
    switch (error.response.status) {
      case 403:
        break
      case 500:
        break
      case 404:
        break
      case 504:
        break
      case 401:
        break
      default:
        break
    }
  }
  return Promise.reject(error)
};

// request interceptor
service.interceptors.request.use(config => {
  if(config.method=='get'){
    config.params = {
      _t: Date.parse(new Date())/1000,
      ...config.params
    }
  }
  return config
},(error) => {
  return Promise.reject(error)
})

// response interceptor
service.interceptors.response.use((response) => {
    return response.data
  }, err)

export function request({url,method='get',data={},params={}}){
  return axios({
    url: url,
    method:method ,
    data: data,
    params: params
  })
}


